<?php
/************************************************************************
 Omnitrix - PHP Development Framework
 Copyright (C) 2012-2018 amonest(eastson@outlook.com)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
************************************************************************/

$GLOBALS['_XJSTEXTS'] = array();
$GLOBALS['_XRESPONSE'] = null;

function otx_html_escape($s)
{
	return htmlspecialchars($s);
}

function otx_html_newline($n = 1)
{
	for ($html = ''; $n > 0; $n--) {
		$html .= "\n";
	}
	return $html;
}

function otx_html_indent($n = 1)
{
	for ($html = ''; $n > 0; $n--) {
		$html .= '    ';
	}
	return $html;
}

function otx_html_js_text($key, $text)
{
	$GLOBALS['_XJSTEXTS'][$key] = $text;
}

function otx_html_next_id($prefix = null)
{
	static $ids = array();

	if (null == $prefix) {
		$prefix = 'id';
	}

	if (empty($ids[$prefix])) {
		$ids[$prefix] = 0;
	}

	$ids[$prefix] = $ids[$prefix] + 1;
	return $prefix . '-' . $ids[$prefix];
}

// function otx_html_attribs($attribs)
// {
// 	$attribs = (array) $attribs;

// 	foreach ($attribs as $key => $value) {
// 		$attribs[$key] = otx_html_escape($key) . '="' . otx_html_escape($value) . '"';
// 	}

// 	if (empty($attribs)) {
// 		return '';
// 	} else {
// 		return ' ' . implode(' ', $attribs);
// 	}
// }

// function otx_html_breadcrumbs($breadcrumbs, $page_title = null)
// {
// 	foreach ($breadcrumbs as $i => $breadcrumb) {
// 		$breadcrumbs[$i] = '<li>'
// 				. '<a href="' . $breadcrumb['href'] . '"'
// 						. (isset($breadcrumb['target']) ? ' target="' . $breadcrumb['target'] . '"' : '')
// 						. '>' . $breadcrumb['text'] . '</a>'
// 								. ($i < count($breadcrumbs) - 1 || !empty($page_title) ? '<span class="divider">/</span>' : '')
// 								. '</li>';
// 	}

// 	return '<div class="block-box breadcrumbs"><ul>'
// 			. implode('', $breadcrumbs)
// 			. (!empty($page_title) ? '<li class="active">' . $page_title . '</li>' : '')
// 			. '</ul></div>';
// }

// function otx_html_block_header($header_title, $header_actions = array())
// {
// 	foreach ($header_actions as $i => $header_action) {
// 		$header_actions[$i] = '<input type="button" class="button"'
// 				. ' value="' . $header_action['text'] . '"'
// 						. ' data-url="' . $header_action['href'] . '"'
// 								. ' />';
// 	}

// 	return '<div class="block-header">'
// 			. '<div class="header-title">' . $header_title . '</div>'
// 					. (count($header_actions) > 0 ? '<div class="header-actions">' . implode('', $header_actions) . '</div>' : '')
// 					. '</div>';
// }

// function otx_html_table_list($columns, $rows, $pager, $key_column = null,
// 		$selectable = true, $manageable = true, $actions = array(), $extras = array())
// {
// 	foreach (explode(',', $columns) as $column_name) {
// 		$column_info = array();

// 		$column_name = trim($column_name);
// 		if (strpos($column_name, ':')) {
// 			list($column_name, $params) = explode(':', $column_name);
// 			$column_name = trim($column_name);

// 			$params = explode('/', trim($params));
// 			foreach ($params as $param_index => $param_value) {
// 				$param_value = trim($param_value);
// 				switch ($param_index) {
// 					case 0:
// 						if (in_array($param_value, array('true', '1'))) {
// 							$column_info['sortable'] = $column_name;
// 						} else if (in_array($param_value, array('false', '0'))) {
// 							$column_info['sortable'] = false;
// 						} else {
// 							$column_info['sortable'] = $param_value;
// 						}
// 						break;
// 					case 1:
// 						$column_info['align'] = $param_value;
// 						break;
// 				}
// 			}
// 		}

// 		$column_info['name'] = $column_name;

// 		if (array_key_exists($column_name, $extras)) {
// 			$column_info = array_merge($column_info, (array) $extras[$column_name]);
// 		}

// 		if (!array_key_exists('sortable', $column_info)) {
// 			$column_info['sortable'] = $column_name;
// 		}

// 		if (!array_key_exists('align', $column_info)) {
// 			$column_info['align'] = 'left';
// 		}

// 		if (!array_key_exists('title', $column_info)) {
// 			$column_info['title'] = otx_language_parse('column_' . $column_name);
// 		}

// 		if (is_string($columns)) {
// 			$columns = array();
// 		}
// 		$columns[$column_name] = $column_info;
// 	}

// 	$table_headers = $table_rows = $table_footers = array();

// 	if ($selectable) {
// 		$table_headers[] = '<th width="1%"><input type="checkbox" /></th>';
// 	}

// 	foreach ($columns as $column_info) {
// 		$table_headers[] = '<th'
// 				. ($column_info['align'] <> 'left' ? ' align="' . $column_info['align'] . '"' : '')
// 				. '>'
// 						. ($column_info['sortable'] ? '<a href="#" data-sort="' . $column_info['sortable'] . '" data-order="' . ($column_info['sortable'] <> $pager['sort_by'] ? 'ASC' : ($pager['sort_order'] == 'ASC' ? 'DESC' : 'ASC')) . '">' : '')
// 						. $column_info['title']
// 						. ($column_info['sortable'] ? '</a>' : '')
// 						. '</th>';
// 	}

// 	if ($manageable) {
// 		$table_headers[] = '<th class="actions-column">' . otx_language_parse('column_actions') . '</th>';
// 	}

// 	if (count($rows) > 0) {
// 		foreach ($rows as $row) {
// 			$table_cells = array();

// 			if ($selectable) {
// 				$table_cells[] = '<td><input name="checked_ids[]" type="checkbox"' . (isset($row[$key_column]) ? ' value="' . $row[$key_column] . '"' : '') . ' /></td>';
// 			}

// 			foreach ($columns as $column_info) {
// 				if (isset($row[$column_info['name']])) {
// 					$cell_value = $row[$column_info['name']];
// 					if (is_string($cell_value) && trim($cell_value) == '') {
// 						$cell_value = '&nbsp;';
// 					}
// 				} else {
// 					$cell_value = '&nbsp;';
// 				}

// 				if (isset($extras[$column_info['name']])) {
// 					$column_extra = (array) $extras[$column_info['name']];

// 					if (isset($column_extra['href'])) {
// 						$display_type = 'link';
// 					} else {
// 						$display_type = 'text';
// 					}

// 					switch ($display_type) {
// 						case 'link':
// 							if (isset($column_extra['href'])) {
// 								$link_href = isset($row[$column_extra['href']]) ? $row[$column_extra['href']] : $column_extra['href'];
// 							} else {
// 								$link_href = '#';
// 							}
// 							if (isset($column_extra['target'])) {
// 								$link_target = isset($row[$column_extra['target']]) ? $row[$column_extra['target']] : $column_extra['target'];
// 							} else {
// 								$link_target = '';
// 							}
// 							$cell_display = '<a href="' . $link_href . '"'
// 									. (!empty($link_target) ? ' target="' . $link_target . '"' : '')
// 									. '>' . $cell_value . '</a>';
// 							break;

// 						case 'text':
// 							$cell_display = $cell_value;
// 							break;
// 					}
// 				} else {
// 					$cell_display = $cell_value;
// 				}

// 				$table_cells[] = '<td'
// 						. ($column_info['align'] <> 'left' ? ' align="' . $column_info['align'] . '"' : '')
// 						. '>' . $cell_display . '</td>';
// 			}

// 			if ($manageable) {
// 				if (empty($row['actions'])) {
// 					$row_actions = array();
// 				} else {
// 					$row_actions = (array) $row['actions'];
// 				}

// 				foreach ($row_actions as &$row_action) {
// 					$row_action = '<a href="' . $row_action['href'] . '"'
// 							. (isset($row_action['target']) ? ' target="' . $row_action['target'] . '"' : '')
// 							. '>' . otx_html_escape($row_action['text']) . '</a>';
// 				}

// 				$table_cells[] = '<td class="actions-column">'
// 						. (count($row_actions) > 0 ? implode('<span class="divider">|</span>', $row_actions) : '&nbsp;')
// 						. '</td>';
// 			}

// 			$table_rows[] = '<tr>' . implode('', $table_cells) . '</tr>';
// 		}


// 		$list_actions = $list_records = $list_pagination = array();

// 		$actions = (array) $actions;
// 		if (count($actions) > 0) {
// 			$list_actions[] = '<select class="bulk-actions">';
// 			$list_actions[] = '<option value="">' . otx_language_parse('text_select') . '</option>';

// 			foreach ($actions as $action) {
// 				$list_actions[] = '<option value="' . $action['action'] . '">' . $action['text'] . '</option>';
// 			}

// 			$list_actions[] = '</select>';
// 			$list_actions[] = '<input type="button" class="button button-bulk" value="执行" />';
// 		}

// 		$list_records[] = otx_language_parse('text_pagination', $pager);

// 		$list_pagination[] = '<input type="button" value="' . otx_language_parse('text_go_first') . '" data-page="1"' . ($pager['current_page'] == 1 ? ' disabled="disabled"' : '') . ' />';
// 		$list_pagination[] = '<input type="button" value="' . otx_language_parse('text_go_previous') . '" data-page="' . ($pager['current_page'] > 1 ? $pager['current_page'] - 1 : 1) . '"' . ($pager['current_page'] == 1 ? ' disabled="disabled"' : '') . ' />';
// 		$list_pagination[] = '<select class="pager">';
// 		for ($page_index = 1; $page_index <= $pager['page_count']; $page_index++) {
// 			$list_pagination[] = '<option value="' . $page_index . '"' . ($pager['current_page'] == $page_index ? ' selected="selected"' : '') . '>' . otx_language_parse('text_go_page', $page_index) . '</option>';
// 		}
// 		$list_pagination[] = '</select>';
// 		$list_pagination[] = '<input type="button" value="' . otx_language_parse('text_go_next') . '" data-page="' . ($pager['current_page'] < $pager['page_count'] ? $pager['current_page'] + 1 : $pager['page_count']) . '"' . ($pager['current_page'] == $pager['page_count'] ? ' disabled="disabled"' : '') . ' />';
// 		$list_pagination[] = '<input type="button" value="' . otx_language_parse('text_go_last') . '" data-page="' . $pager['page_count'] . '"' . ($pager['current_page'] == $pager['page_count'] ? ' disabled="disabled"' : '') . ' />';

// 		$table_footers[] = '<tr><td colspan="99">'
// 				. '<div class="list-actions">' . (count($list_actions) ? implode("\n", $list_actions) : '&nbsp;') . '</div>'
// 						. '<div class="list-records">' . (count($list_records) ? implode("\n", $list_records) : '&nbsp;') . '</div>'
// 								. '<div class="list-pagination">' . (count($list_pagination) ? implode("\n", $list_pagination) : '&nbsp;') . '</div>'
// 										. '</td></tr>';
// 	} else {
// 		$table_footers[] = '<tr class="no-records">'
// 				. '<td colspan="99">' . otx_language_parse('text_no_results') . '</td>'
// 						. '</tr>';
// 	}

// 	return '<table class="table-list"'
// 			. ' data-sort="' . $pager['sort_by'] . '"'
// 					. ' data-order="' . $pager['sort_order'] . '"'
// 							. ' data-page="' . $pager['current_page'] . '"'
// 									. '>'
// 											. '<thead><tr>' . implode("\n", $table_headers) . '</tr></thead>'
// 													. (count($table_rows) > 0 ? '<tbody>' . implode("\n", $table_rows) . '</tbody>' : '')
// 													. (count($table_footers) > 0 ? '<tfoot>' . implode("\n", $table_footers) . '</tfoot>' : '')
// 													. '</table>';
// }

// function otx_html_form_label($name, $value, $attribs = array())
// {
// 	$attribs = (array) $attribs;
// 	return '<label'
// 			. (!empty($name) ? ' for="' . otx_html_escape($name) . '"' : '')
// 			. otx_html_attribs($attribs)
// 			. '>' . $value . '</label>';
// }

function otx_html_form_text($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;

	if (array_key_exists('type', $attribs)) {
		$type = $attribs['type'];
		unset($attribs['type']);
	} else {
		$type = 'text';
	}

	if (array_key_exists('class', $attribs)) {
		$class = $attribs['class'];
		unset($attribs['class']);
	} else {
		if (in_array($type, array('button', 'submit', 'reset'))) {
			$class = 'button';
		} else if (in_array($type, array('hidden'))) {
			$class = null;
		} else {
			$class = 'control-large';
		}
	}

	if (array_key_exists('disabled', $attribs)) {
		$disabled = (bool) $attribs['disabled'];
		unset($attribs['disabled']);
	} else {
		$disabled = false;
	}

	if (array_key_exists('required', $attribs)) {
		$required = (bool) $attribs['required'];
		unset($attribs['required']);
	} else {
		$required = false;
	}

	return '<input type="' . $type . '"'
			. ' value="' . otx_html_escape($value) . '"'
					. (!empty($name) ? ' name="' . otx_html_escape($name) . '"' : '')
					. (!empty($class) ? ' class="' . otx_html_escape($class) . '"' : '')
					. ($disabled ? ' disabled="disabled"' : '')
					. otx_html_tag_attribs($attribs)
					. ' />'
							. ($required ? otx_html_form_required() : '');
}

function otx_html_form_hidden($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;
	$attribs['type'] = 'hidden';
	return otx_html_form_text($name, $value, $attribs);
}

function otx_html_form_password($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;
	$attribs['type'] = 'password';
	return otx_html_form_text($name, $value, $attribs);
}

function otx_html_form_number($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;
	$attribs['type'] = 'number';
	return otx_html_form_text($name, $value, $attribs);
}

function otx_html_form_button($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;
	if (!array_key_exists('type', $attribs)) {
		$attribs['type'] = 'button';
	}
	return otx_html_form_text($name, $value, $attribs);
}

function otx_html_form_checkbox($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;
	$attribs['type'] = 'checkbox';

	if (array_key_exists('label', $attribs)) {
		$label = $attribs['label'];
		unset($attribs['label']);

		$label_attribs = array();
		foreach ($attribs as $k => $v) {
			if (substr($k, 0, 6) == 'label-') {
				$label_attribs[substr($k, 6)] = $v;
				unset($attribs[$k]);
			}
		}
	}

	if (isset($label)) {
		return otx_html_tag_start('label', $label_attribs)
				. otx_html_form_text($name, $value, $attribs)
				. $label
				. otx_html_tag_end('label');

	} else {
		return otx_html_form_text($name, $value, $attribs);
	}
}

function otx_html_form_radio($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;
	$attribs['type'] = 'radio';

	if (array_key_exists('label', $attribs)) {
		$label = $attribs['label'];
		unset($attribs['label']);

		$label_attribs = array();
		foreach ($attribs as $k => $v) {
			if (substr($k, 0, 6) == 'label-') {
				$label_attribs[substr($k, 6)] = $v;
				unset($attribs[$k]);
			}
		}
	}

	if (isset($label)) {
		return otx_html_tag_start('label', $label_attribs)
			. otx_html_form_text($name, $value, $attribs)
			. $label
			. otx_html_tag_end('label');

	} else {
		return otx_html_form_text($name, $value, $attribs);
	}
}

function otx_html_form_radiolist($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;
	$html = '';

	if (array_key_exists('options', $attribs)) {
		$options = (array) $attribs['options'];
		unset($attribs['options']);
	} else {
		$options = array();
	}

	foreach ($options as $key => $label) {
		$radio_attribs = $attribs;
		$radio_attribs['label'] = $label;
		if ($key == $value) {
			$radio_attribs['checked'] = 'checked';
		}
		$html .= otx_html_form_radio($name, $key, $radio_attribs);
	}

	return $html;
}

function otx_html_form_textarea($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;

	if (array_key_exists('rows', $attribs)) {
		$rows = $attribs['rows'];
		unset($attribs['rows']);
	}

	if (array_key_exists('cols', $attribs)) {
		$cols = $attribs['cols'];
		unset($attribs['cols']);
	}

	if (array_key_exists('class', $attribs)) {
		$class = $attribs['class'];
		unset($attribs['class']);
	} else {
		$class = 'control-large';
	}

	if (array_key_exists('disabled', $attribs)) {
		$disabled = (bool) $attribs['disabled'];
		unset($attribs['disabled']);
	} else {
		$disabled = false;
	}

	if (array_key_exists('required', $attribs)) {
		$required = (bool) $attribs['required'];
		unset($attribs['required']);
	} else {
		$required = false;
	}

	return '<textarea'
			. (!empty($name) ? ' name="' . otx_html_escape($name) . '"' : '')
			. (!empty($rows) ? ' rows="' . otx_html_escape($rows) . '"' : '')
			. (!empty($cols) ? ' cols="' . otx_html_escape($cols) . '"' : '')
			. (!empty($class) ? ' class="' . otx_html_escape($class) . '"' : '')
			. ($disabled ? ' disabled="disabled"' : '')
			. otx_html_tag_attribs($attribs)
			. '>' . otx_html_escape($value) . '</textarea>'
					. ($required ? otx_html_form_required() : '');
}

function otx_html_form_select($name, $value, $attribs = array())
{
	$attribs = (array) $attribs;

	if (array_key_exists('class', $attribs)) {
		$class = $attribs['class'];
		unset($attribs['class']);
	} else {
		$class = 'control-large';
	}

	if (array_key_exists('disabled', $attribs)) {
		$disabled = (bool) $attribs['disabled'];
		unset($attribs['disabled']);
	} else {
		$disabled = false;
	}

	if (array_key_exists('required', $attribs)) {
		$required = (bool) $attribs['required'];
		unset($attribs['required']);
	} else {
		$required = false;
	}

	if (array_key_exists('options', $attribs)) {
		$options = (array) $attribs['options'];
		unset($attribs['options']);
	} else {
		$options = array();
	}

	return '<select'
			. (!empty($name) ? ' name="' . otx_html_escape($name) . '"' : '')
			. (!empty($class) ? ' class="' . otx_html_escape($class) . '"' : '')
			. ($disabled ? ' disabled="disabled"' : '')
			. otx_html_tag_attribs($attribs)
			. '>' . otx_html_form_options($options, $value) . '</select>'
					. ($required ? otx_html_form_required() : '');
}

function otx_html_form_options($options, $selected = null)
{
	$list = array();
	$selected = (array) $selected;

// 	if (!isset($options[0])) {
// 		$options = array_merge(array(otx_language_parse('text_select')), $options);
// 	}

	foreach ($options as $opt_value => $opt_label) {
		if (is_array($opt_label)) {
			$list[] = '<optgroup'
					. ' label="' . otx_html_escape($opt_value) .'">'
							. otx_html_form_options($opt_label)
							. '</optgroup>';
		} else {
			$list[] = '<option'
					. ' value="' . otx_html_escape($opt_value) . '"'
							. ' label="' . otx_html_escape($opt_label) . '"'
									. (strlen($opt_value) > 0 && in_array($opt_value, $selected) ? ' selected="selected"' : '')
									. '>' . otx_html_escape($opt_label) . "</option>";
		}
	}

	return implode('', $list);
}

function otx_html_form_yesno($name, $value, $attribs = array())
{
	return otx_html_tag_start('label', array('class' => 'label-radio-yes'))
			. otx_html_form_radio($name, 1, array_merge($attribs, $value ? array('checked' => 'checked') : array()))
			. otx_language_parse('text_yes')
			. otx_html_tag_end('label')
			. otx_html_tag_start('label', array('class' => 'label-radio-no'))
			. otx_html_form_radio($name, 0, array_merge($attribs, !$value ? array('checked' => 'checked') : array()))
			. otx_language_parse('text_no')
			. otx_html_tag_end('label');
}

function otx_html_form_onoff($name, $value, $attribs = array())
{
	return otx_html_tag_start('label', array('class' => 'label-radio-on'))
			. otx_html_form_radio($name, 1, array_merge($attribs, $value ? array('checked' => 'checked') : array()))
			. otx_language_parse('text_on')
			. otx_html_tag_end('label')
			. otx_html_tag_start('label', array('class' => 'label-radio-off'))
			. otx_html_form_radio($name, 0, array_merge($attribs, !$value ? array('checked' => 'checked') : array()))
			. otx_language_parse('text_off')
			. otx_html_tag_end('label');
}

// function otx_html_form_actions()
// {
// 	return '<tr class="form-actions"><td colspan="99">'
// 			. otx_html_form_button(null, otx_language_parse('button_save'), array('class' => 'button button-save'))
// 			. otx_html_form_button(null, otx_language_parse('button_return'), array('class' => 'button button-return'))
// 			. '</td></tr>';
// }

// function otx_html_form_row($type, $name, $value, $attribs = array())
// {
// 	$attribs = (array) $attribs;

// 	if (array_key_exists('label', $attribs)) {
// 		$label = $attribs['label'];
// 		unset($attribs['label']);
// 	} else {
// 		$label = otx_language_parse('entry_' . $name);
// 	}

// 	return '<tr>'
// 			. '<td>' . otx_html_form_label($name, $label, array()) . '</td>'
// 					. '<td>' . call_user_func('otx_html_form_' . $type, $name, $value, $attribs) . '</td>'
// 							. '</tr>';
// }

// function otx_html_form_section($title)
// {
// 	return '<tr class="form-section"><td colspan="99">' . $title . '</td></tr>';
// }

// function otx_html_form_required()
// {
// 	return '<span class="required-mark">*</span>';
// }

function otx_html_tag_attribs($tag_attribs)
{
	$tag_attribs = (array) $tag_attribs;

	foreach ($tag_attribs as $key => $value) {
		$tag_attribs[$key] = otx_html_escape($key) . '="' . otx_html_escape($value) . '"';
	}

	if (empty($tag_attribs)) {
		return '';
	} else {
		return ' ' . implode(' ', $tag_attribs);
	}
}

function otx_html_tag_simple($tag_name, $tag_content, $tag_attribs = array())
{
	if (empty($tag_content)) {
		return otx_html_tag_empty($tag_name, $tag_attribs);
	} else {
		return otx_html_tag_start($tag_name, $tag_attribs)
		. $tag_content
		. otx_html_tag_end($tag_name);
	}
}

function otx_html_tag_start($tag_name, $tag_attribs = array())
{
	return '<' . $tag_name
			. otx_html_tag_attribs($tag_attribs)
			. '>';
}

function otx_html_tag_empty($tag_name, $tag_attribs = array())
{
	return '<' . $tag_name
			. otx_html_tag_attribs($tag_attribs)
			. ' />';
}

function otx_html_tag_end($tag_name)
{
	return '</' . $tag_name . '>';
}

function otx_html_tag_custom($tag_name)
{
	$args = func_get_args();
	array_shift($args);

	if (false === strpos($tag_name, '/')) {
		$tag_class = 'omnitrix_html_' . $tag_name;
	} else {
		list($module_name, $tag_name) = explode('/', $tag_name);
		$tag_file = otx_module_path($module_name, 'includes/html_' . $tag_name . '.php');
		require_once $tag_file;
		$tag_class = $module_name . '_html_' . $tag_name;
	}

	$tag_reflection = new ReflectionClass($tag_class);
	$tag_object = $tag_reflection->newInstanceArgs($args);
	return $tag_object;
}

function otx_html_link($content, $attribs = array(), $strong = false)
{
	return otx_html_tag_simple('a', $strong ? otx_html_strong($content) : $content, $attribs);
}

function otx_html_strong($content, $attribs = array())
{
	return otx_html_tag_simple('strong', $content, $attribs);
}

function otx_html_small($content, $attribs = array())
{
	return otx_html_tag_simple('small', $content, $attribs);
}

function otx_html_span($content, $attribs = array())
{
	return otx_html_tag_simple('span', $content, $attribs);
}

function otx_html_response_instance()
{
	if (null === $GLOBALS['_XRESPONSE']) {
		$GLOBALS['_XRESPONSE'] = otx_html_tag_custom('response');
	}
	return $GLOBALS['_XRESPONSE'];
}

function otx_html_response_output()
{
	echo otx_html_response_instance();
}

function otx_html_response_title($title)
{
	otx_html_response_instance()->set_title($title);
}

function otx_html_add_breadcrumb($text, $link = null)
{
	otx_html_response_instance()->add_breadcrumb($text, $link);
}

function otx_html_add_navtab($title, $description, $link, $active = false)
{
	otx_html_response_instance()->add_navtab($title, $description, $link, $active);
}

function otx_html_add_child($child)
{
	otx_html_response_instance()->add_child($child);
}

function otx_html_create_message($class = null)
{
	return otx_html_response_instance()->create_message($class);
}

function otx_html_create_wrapper($form_action = null, $form_method = null, $submit_button = true)
{
	return otx_html_response_instance()->create_wrapper($form_action, $form_method, $submit_button);
}

function otx_html_create_table($title = null, $class = null, $pager_info = null, $link_pattern = null)
{
	return otx_html_response_instance()->create_table($title, $class, $pager_info, $link_pattern);
}